﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ObserverPattern
{
    class Program
    {
        static void Main(string[] args)
        {
            Random random = new Random();
            int randint;
            Stock stock = new Stock() { Name = "Jyske Bank", Value = 100 };
            Stock stock2 = new Stock() { Name = "Nordea    ", Value = 100 };
            Portfolio portfolio1 = new Portfolio() { Name = "Martin's stocks" };
            portfolio1.AddStock(stock);
            portfolio1.AddStock(stock);
            portfolio1.AddStock(stock2);

            while (true)
            {
                randint = random.Next(0,2);
                System.Threading.Thread.Sleep(1000);
                if (randint == 0)
                {
                    stock.Value = stock.Value*0.9;
                    stock.Notify();
                    stock2.Value = stock.Value * 0.8;
                    stock2.Notify();
                }
                else
                {
                    stock.Value = stock.Value *1.2;
                    stock.Notify();
                    stock2.Value = stock.Value * 1.1;
                    stock2.Notify();
                }
                
            }

            
        }
    }
}
